﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public class TacGiaDAO
    {
        public DataTable LayTable()
        {
            String sql = "SELECT * from TacGia ";
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            DataTable dt = new DataTable();
            adapter.Fill(dt);

            con.Close();
            return dt;
        }
        public void them(TacGiaDTO tg)
        {
            String sql = "Insert into TacGia(TenTG) values(N'" + tg.TenTG + "')";
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);
            int res = -1;
            res = command.ExecuteNonQuery();
            con.Close();
        }

        public void sua(TacGiaDTO tg)
        {
            String sql = "UPDATE TacGia SET TenTG=N'" + tg.TenTG + "' where MaTG =" + tg.MaTG;
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);
            int res = -1;
            res = command.ExecuteNonQuery();
            con.Close();
        }
        public void Xoa(TacGiaDTO tg)
        {
            String sql = "delete TacGia  where MaTG =" + tg.MaTG;
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);
            int res = -1;
            res = command.ExecuteNonQuery();
            con.Close();
        }
    }
}
